import org.lwjgl.Sys;


public class DeltaTimer {

	private long previousTick;
	private int frameCount;
	private long lastSecTick;
	private int fps;
	private int delta;
	
	
	public DeltaTimer() {
		previousTick = getSysTime();
		frameCount = 0;
		lastSecTick = 0;
		fps = 0;
		delta = 0;
	}

	public void tick(){
		long now = getSysTime();
		//update Delta
		delta = (int) (now - previousTick);
		previousTick = now;
		//update FPS
		if (getSysTime() - lastSecTick > 1000) {
			fps = frameCount;
			frameCount = 0;
			lastSecTick = now;
		}
		frameCount++;
	}
	
	public int getDelta() {
	    return delta;
	}
	
	public int getFPS(){
		return fps;
	}
	
	private long getSysTime() {
	    return (Sys.getTime() * 1000) / Sys.getTimerResolution();
	}
	
}
